<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">

    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">店铺名称:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-shop_name" class="form-control" data-rule="required" name="row[shop_name]" type="text" value="{$row.shop_name|htmlentities}" data-role="autocomplete" data-autocomplete-options='{"url":"shops/shop/autocomplete","onCache":true}'>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">平台选择:</label>
        <div class="col-xs-12 col-sm-8">
                        
            <select  id="c-shop_type" data-rule="required" class="form-control selectpicker" name="row[shop_type]">
                {foreach name="shopTypeList" item="vo"}
                    <option value="{$key}" {if $key==$row.shop_type}selected{/if}>{$vo}</option>
                {/foreach}
            </select>

        </div>
    </div>
    <!-- <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">所属商家:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-have_uid" data-rule="required" data-field="nickname" data-source="shops/shops/index" class="form-control selectpage" name="row[have_uid]" type="text" value="{$row.have_uid|htmlentities}" data-search-field="nickname,id">
        </div>
    </div> -->
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">店铺类型:</label>
        <div class="col-xs-12 col-sm-8">
                        
            <select  id="c-category_no" data-rule="required" class="form-control selectpicker" name="row[category_no]">
                <option value="">请选择</option>
                {foreach name="shopCategory" item="vo"}
                    <option value="{$key}" {if $row.category_no==$key}selected{/if}>{$vo}</option>
                {/foreach}
            </select>

        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">店铺区域:</label>
        <div class="col-xs-12 col-sm-8">
                        
            <input id="c-city" class="form-control" data-rule="required" placeholder="请选择省/市" data-responsive="true" data-level="district"  data-toggle="city-picker" name="row[shop_area]" type="text" value="{$row.shop_area|htmlentities}" />

        </div>
    </div>
    <!--<div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Category_id')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-category_id" data-rule="required" data-source="category/selectpage" data-params='{"custom[type]":"shop"}' class="form-control selectpage" name="row[category_id]" type="text" value="">
        </div>
    </div>-->
    <!--<div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Logo')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input  id="c-logo" class="form-control" name="row[logo]" type="text">
        </div>
    </div>-->
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Address')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-address1" class="form-control" name="row[address]" type="text" value="{$row.address|htmlentities}" data-rule="required">
            <input id="c-address" class="form-control" type="hidden" value="{$row.address|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">纬度:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-lat" class="form-control" step="0.000001" name="row[lat]" type="number" value="{$row.lat|htmlentities}" data-rule="required">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Lng')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-lng" class="form-control" step="0.000001" name="row[lng]" type="number" value="{$row.lng|htmlentities}" data-rule="required">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">位置信息:</label>
        <div class="col-xs-12 col-sm-8">
            <button type="button" data-toggle="addresspicker" data-lat-id="c-lat" data-lng-id="c-lng" data-input-id="c-address" class="btn btn-primary" ><i class="fa fa-list"></i> 选择</button>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">商家号码:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-phone" class="form-control" name="row[phone]" type="text" value="{$row.phone|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">是否商家自配:</label>
        <div class="col-xs-12 col-sm-8">
                        
            <select  id="c-is_sjzp" data-rule="required" class="form-control selectpicker" name="row[is_sjzp]">
                <option value="0" {if 0==$row.is_sjzp}selected{/if}>否</option>
                <option value="1" {if 1==$row.is_sjzp}selected{/if}>是</option>
            </select>

        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">营业时间:</label>
        <div class="col-xs-12 col-sm-8">
            <input data-rule="required" id="c-business_time_start" type="text" class="form-control datetimepicker" data-date-format="HH:mm" placeholder="开始时间，例：10:00" name="row[business_time_start]" value="{$business_time_start|htmlentities}" style="width: 40%" />
            至
            <input data-rule="required" id="c-business_time_end" type="text" class="form-control datetimepicker" data-date-format="HH:mm" placeholder="结束时间，例：14:00" name="row[business_time_end]" value="{$business_time_end|htmlentities}" style="width: 40%" />
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Logo')}:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-logo_pic" data-rule="required" class="form-control" size="50" name="row[logo_pic]" type="text" value="{$row.logo_pic|htmlentities}">
                <div class="input-group-addon no-border no-padding">
                    <span><button type="button" id="faupload-logo_pic" class="btn btn-danger faupload" data-input-id="c-logo_pic" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="false" data-preview-id="p-logo_pic"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                    <span><button type="button" id="fachoose-logo_pic" class="btn btn-primary fachoose" data-input-id="c-logo_pic" data-mimetype="image/*" data-multiple="false"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
                </div>
                <span class="msg-box n-right" for="c-logo_pic"></span>
            </div>
            <ul class="row list-inline faupload-preview" id="p-logo_pic"></ul>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">是否显示二维码进店:</label>
        <div class="col-xs-12 col-sm-8">
            <input type="checkbox" id="c-has_qrcode" name="row[has_qrcode]" value="1" {if $row.has_qrcode==1}checked="checked"{/if}>
        </div>
    </div>
    <div class="form-group" id="qrcode_pic">
        <label class="control-label col-xs-12 col-sm-2">店铺二维码:</label>
        <div class="col-xs-12 col-sm-8">
            <div class="input-group">
                <input id="c-qrcode_pic" class="form-control" size="50" name="row[qrcode_pic]" type="text" value="{$row.qrcode_pic|htmlentities}">
                <div class="input-group-addon no-border no-padding">
                    <span><button type="button" id="faupload-qrcode_pic" class="btn btn-danger faupload" data-input-id="c-qrcode_pic" data-mimetype="image/gif,image/jpeg,image/png,image/jpg,image/bmp,image/webp" data-multiple="true" data-preview-id="p-qrcode_pic"><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
                    <span><button type="button" id="fachoose-qrcode_pic" class="btn btn-primary fachoose" data-input-id="c-qrcode_pic" data-mimetype="image/*" data-multiple="true"><i class="fa fa-list"></i> {:__('Choose')}</button></span>
                </div>
                <span class="msg-box n-right" for="c-qrcode_pic"></span>
            </div>
            <ul class="row list-inline faupload-preview" id="p-qrcode_pic"></ul>
        </div>
        <label class="control-label col-xs-12 col-sm-2" style="text-align: left;"><a href="javascript:;" style="color: red;" id="createQrCode">生成进店二维码</a></label>
    </div>
    <!--<div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Province')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-province" data-rule="required" class="form-control" name="row[province]" type="text" value="">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('City')}:</label>
        <div class="col-xs-12 col-sm-8">
            <div class='control-relative'><input id="c-city" data-rule="required" class="form-control" data-toggle="city-picker" name="row[city]" type="text" value=""></div>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('County')}:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-county" data-rule="required" class="form-control" name="row[county]" type="text" value="">
        </div>
    </div>-->
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">店铺ID:</label>
        <div class="col-xs-12 col-sm-8" style="display: flex;">
            <input id="c-platform_no" class="form-control" name="row[platform_no]" type="text" value="{$row.platform_no|htmlentities}" style="width: 50%;">
            <label>
                <input type="checkbox" id="c-is_xls" name="row[is_xls]" value="1" style="margin-left: 10px;" {if $row.is_xls==1}checked="checked"{/if}>
                <label class="control-label" style="padding-top:0;">新零售</label>
            </label>
            <label id="dpzxelmcheckbox" {if $row.shop_type==1}style="display: none;"{/if}>
                <input type="checkbox" id="c-dpzxelm" name="row[dpzxelm]" value="1" style="margin-left: 10px;" {if $row.dpzxelm==1}checked="checked"{/if}>
                <label class="control-label" style="padding-top:0;">大牌专享</label>
            </label>
        </div>
    </div>
    <div class="form-group" id="elm_appenter">
        <label class="control-label col-xs-12 col-sm-2">APP进店:</label>
        <div class="col-xs-12 col-sm-8">
            <input id="c-elm_appenter" class="form-control" name="row[elm_appenter]" type="text" value="{$row.elm_appenter|htmlentities}">
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">业务员:</label>
        <div class="col-xs-12 col-sm-8">
                        
            <select  id="c-salesman_admin_id" data-rule="required" class="form-control selectpicker" name="row[salesman_admin_id]" data-rule="required">
                <option value="">请选择</option>
                {foreach name="salesmanList" item="vo"}
                    <option value="{$vo.id}" {if $row.salesman_admin_id==$vo.id}selected{/if}>{$vo.nickname}</option>
                {/foreach}
            </select>

        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">经纪人（如有）:</label>
        <div class="col-xs-12 col-sm-8">
                        
            <!-- <select  id="c-middleman_id" class="form-control selectpicker" name="row[middleman_id]">
                <option value="">请选择</option>
                {foreach name="middleman" item="vo"}
                    <option value="{$vo.id}" {if $row.middleman_id==$vo.id}selected{/if}>{$vo.real_name}</option>
                {/foreach}
            </select> -->
            <input id="c-middleman_id" data-field="real_name" data-source="shops/middleman/index" class="form-control selectpage" name="row[middleman_id]" type="text" value="{$row.middleman_id|htmlentities}" data-search-field="real_name,id">

        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">平台服务费:</label>
        <div class="col-xs-12 col-sm-10" id="channel">
            {foreach name="$shop_serviceamt" item="vo" key="k"}
            <div class="flex" >
                <div class="col-xs-12 col-sm-5">
                    <input type="text" name="row[channel_name][]" placeholder="" class="form-control" value="{$vo.channel_name}" readonly="">
                </div>
                <div class="col-xs-12 col-sm-4">
                    <input type="text" name="row[service_amt][]" placeholder="技术服务费" class="form-control" value="{$vo.service_amt}" data-rule="required">
                </div>
            </div>
            {/foreach}
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
        <div class="col-xs-12 col-sm-8">
            
            <div class="radio">
            {foreach name="statusList" item="vo"}
            <label for="row[shop_status]-{$key}"><input id="row[shop_status]-{$key}" name="row[shop_status]" type="radio" value="{$key}"  {if $row.shop_status==$key}checked{/if} /> {$vo}</label>
            {/foreach}
            </div>

        </div>
    </div>
    <div class="form-group layer-footer">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
        </div>
    </div>
</form>

<script src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
<script>
    $('#createQrCode').on('click',function (e) {
        var platform_no = $('#c-platform_no').val()
        var shop_type = $('#c-shop_type').val()
        if (!platform_no) {
            alert('请填写店铺ID参数')
            return false
        }
        var is_xls = $('#c-is_xls').is(':checked')
        var data = {platform_no:platform_no,shop_type:shop_type,is_xls:is_xls}
        $.ajax({
            url:"/hFtNsJROTk.php/shops/shop/createQrcode",
            data: data,
            success:function(result){
                if (result.code==1) {
                    $('#c-qrcode_pic').val(result.data.url)
                    var html = `<li class="col-xs-3"><a href="`+result.data.url+`" data-url="`+result.data.path+`" target="_blank" class="thumbnail"><img src="`+result.data.url+`" onerror="this.src='/hFtNsJROTk.php/ajax/icon?suffix=png';this.onerror=null;" class="img-responsive"></a><a href="javascript:;" class="btn btn-danger btn-xs btn-trash"><i class="fa fa-trash"></i></a></li>`;
                    $('#p-qrcode_pic').html(html);
                } else {
                    alert(result.msg)
                }
            }
        })
    })
    $('#c-elm_appenter').on('change',function (e) {
        var shop_type = $('#c-shop_type').val();
        if (shop_type!=3) return false
        var appenter = $('#c-elm_appenter').val()
        appenter = decodeURI(appenter)
        if (appenter==undefined) {
            $('#c-platform_no').val('')
            return false
        }
        if (appenter.includes('openapp.jdmobile')) {
            var arr = appenter.split("=")
            if (arr[1]==undefined) {
                $('#c-platform_no').val('')
                return false
            }
            var obj = JSON.parse(arr[1])
            if (obj.param.venderId==undefined || obj.param.storeId==undefined) {
                $('#c-platform_no').val('')
                return false
            }
            obj.appId = 'B594E1702946F919D4B3B9C0DA5B4985';
            if (obj.appId==undefined) {
                $('#c-platform_no').val('?bizType=1&venderId='+obj.param.venderId+'&storeId='+obj.param.storeId)
            } else {
                $('#c-platform_no').val('?bizType=1&venderId='+obj.param.venderId+'&storeId='+obj.param.storeId+'&appId='+obj.appId)
            }
        } else if (appenter.includes('desktopicon')) {
            appId = getQueryParam('appId',appenter)
            appName = getQueryParam('appName',appenter)
            appIcon = getQueryParam('appIcon',appenter)
            $('#c-shop_name').val(appName)
            $('#c-platform_no').val(appId)
            $('#c-logo_pic').val(appIcon)
            var html = `<li class="col-xs-3"><a href="`+appIcon+`" data-url="" target="_blank" class="thumbnail"><img src="`+appIcon+`" onerror="this.src='/hFtNsJROTk.php/ajax/icon?suffix=png';this.onerror=null;" class="img-responsive"></a><a href="javascript:;" class="btn btn-danger btn-xs btn-trash"><i class="fa fa-trash"></i></a></li>`;
            $('#p-logo_pic').html(html);
            param = getQueryParam('param',appenter)
            var obj = JSON.parse(param)
            appId = getQueryParam('appId',appenter)
            if (obj.venderId==undefined || obj.storeId==undefined) {
                $('#c-platform_no').val('')
                return false
            }
            appId = 'B594E1702946F919D4B3B9C0DA5B4985';
            if (appId==undefined) {
                $('#c-platform_no').val('?bizType=1&venderId='+obj.venderId+'&storeId='+obj.storeId)
            } else {
                $('#c-platform_no').val('?bizType=1&venderId='+obj.venderId+'&storeId='+obj.storeId+'&appId='+appId)
            }
        } else if (appenter.includes('mini-app-static.jd.com')) {
            var arr = appenter.split("param=")
            if (arr[1]==undefined) {
                $('#c-platform_no').val('')
                return false
            }
            var obj = JSON.parse(arr[1])
            appId = getQueryParam('appId',appenter)
            if (obj.venderId==undefined || obj.storeId==undefined) {
                $('#c-platform_no').val('')
                return false
            }
            appId = 'B594E1702946F919D4B3B9C0DA5B4985';
            if (appId==undefined) {
                $('#c-platform_no').val('?bizType=1&venderId='+obj.venderId+'&storeId='+obj.storeId)
            } else {
                $('#c-platform_no').val('?bizType=1&venderId='+obj.venderId+'&storeId='+obj.storeId+'&appId='+appId)
            }
        } else {
            var venderId=''
            var storeId=''
            venderId = getQueryParam('venderId',appenter)
            if (!venderId) {
                $('#c-platform_no').val('')
                return false
            }
            storeId = getQueryParam('storeId',appenter)
            if (!storeId) {
                $('#c-platform_no').val('')
                return false
            }
            appId = getQueryParam('appId',appenter)
            appId = 'B594E1702946F919D4B3B9C0DA5B4985';
            if (!appId) {
                $('#c-platform_no').val('?bizType=1&venderId='+venderId+'&storeId='+storeId)
            } else {
                $('#c-platform_no').val('?bizType=1&venderId='+venderId+'&storeId='+storeId+'&appId='+appId)
            }
        }
    })

    function getQueryParam(param,query) {
        const regex = new RegExp(`[?&]${param}=([^&#]*)`);
        const results = regex.exec(query);
        return results ? results[1] : null;
    }
 
</script>
